package com.pipayshop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pipayshop.domain.AttributeKey;
import com.pipayshop.domain.Sku;
import com.pipayshop.mapper.OnlineStoreAttributeKeyMapper;
import com.pipayshop.mapper.OnlineStoreSkuMapper;
import com.pipayshop.service.OnlineStoreSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xiaoqiu
 * @date 2024/12/11 17:10
 * @description
 */
@Service
public class OnlineStoreSkuServiceImpl extends ServiceImpl<OnlineStoreSkuMapper, Sku> implements OnlineStoreSkuService {
    @Autowired
    private OnlineStoreAttributeKeyMapper attributeKeyMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, List<String>> listSku(Integer categoryId) {
        HashMap<String,List<String>> HashMap = new HashMap<>();

        //根据分类id获取属性名对象
        List<AttributeKey> attributeNameList = attributeKeyMapper.listAttributeName(categoryId);
        //遍历属性名对象 根据属性名id获取属性值
        for (AttributeKey attributeKey : attributeNameList) {
            Integer id = attributeKey.getId();
            List<String> attributeValueList = attributeKeyMapper.listAttributeValue(id);
            //将属性名与属性值列表添加到集合中
            HashMap.put(attributeKey.getAttributeKeyName(),attributeValueList);
        }
        return HashMap;
    }
}
